import { createMemoryHistory, createRouter } from 'vue-router'

import home from '@/pages/home.vue'
import ordersure from '@/pages/ordersure.vue'
import myorder from '@/pages/myorder.vue'
import Orderdetail from '@/pages/orderdetail.vue'
import Login from '@/pages/login.vue'
import pinia from '@/store'
import { useUserStore } from '@/store/module/user'

const routes = [
  { path: '/', component: home },
  { path: '/ordersure', component: ordersure },
  { path: '/orderdetail', component: Orderdetail },
  { path: '/myorder', component: myorder },
  { path: '/login', component: Login }
]

const router = createRouter({
  history: createMemoryHistory(),
  routes,
})

const userStore = useUserStore(pinia)

router.beforeEach((to,from)=>{
    if(to.path!='/login'&&!userStore.isLogin){
      return '/login'
    }
})

export default router